package com.zazu.mycl.application.commands;

import java.io.File;

import com.zazu.mycl.application.AbstractTerminalCommand;
import com.zazu.mycl.application.CommandRunner;
import com.zazu.mycl.application.constants;

public class ListDirectoryCommand extends AbstractTerminalCommand {

	@Override
	public void run(String[] args, CommandRunner commandRunner,
			String commandLine, String outputFileName) {

		String myDir = commandRunner.getVariable(constants.CURRENT_DIRECTORY);
		
		this.commandRunner = commandRunner;
		
		commandRunner.SetLine("Getting file info for: "+myDir);
		
		File f = new File(myDir);
		
		listFiles(f, true, "NamesOnly");
	}

	public void listFiles(File f, boolean showHidden, String showInfoType)
	{
		File[] files = f.listFiles();
		
		if(files.length != 0)
		{
			if(showInfoType.equals("NamesOnly"))
			{
				for(File file : files)
				{
					commandRunner.SetLine("\t"+getFileInd(file)+"\t"+file.getName());
				}
			}	
			else if(showInfoType.equals("Full"))
			{
				
			}
			else
			{
			
			}
		}
		else
		{
			commandRunner.SetLine("\t[Empty]");
		}
		
	}
	
	private String getFileInd(File f)
	{
		if(f.isDirectory())
		{
			return "DIR";
		}
		else
		{
			return "";
		}
	}
	
	@Override
	public void runSubCommand(String[] args, String commandLine) {
		// TODO Auto-generated method stub

	}

	public String getSignature() {
		// TODO Auto-generated method stub
		return "showHiddenFiles(True|False),showInfo(Full|NamesOnly)";
	}

	public boolean isThreadable() {
		// TODO Auto-generated method stub
		return isThreadable;
	}

	private boolean isThreadable = true;
	private CommandRunner commandRunner;
	
}
